load('NN_ver2.mat');

preY=net(Xtrain');

preLabel=round(preY);%四舍五入成0或1

ACC_NN = sum(preLabel==Ytrain') / numel(Ytrain');

ACC_NN_LMKF=0;

q=0.01;
r=0.01;
maxEpoch=500;

%Ytrain信号添加噪声
noise=sqrt(r)*randn(size(Ytrain));
Yzk=Ytrain+noise;
for i=1:size(Ytrain,1)
    if(Yzk(i)<0)
        Yzk(i)=0;
    end
end

while(ACC_NN_LMKF==0)
    Q=q*eye(14);
    R=r*eye(1);
    x0=zeros(14, 1);
    P0=eye(14);
    for i=1:maxEpoch
        if(i==1)
            x_=x0;
            P=P0;
        end
        x_group=[];
        H_group=[];
        for k=1:size(Ytrain,1)
            H=[preY(k),Xtrain(k,:)];
            xs_=x_;
            P_=P+Q;
            K=P_*H'*inv(H*P_*H'+R);
            x_=xs_+K*(Yzk(k)-H*xs_);
            P=(eye(14)-K*H)*P_;
            %
            x_group=[x_group,x_];
            H_group=[H_group;H];
        end
        z_group=[];
        err_z=[];
        for k=1:size(Ytrain,1)
            z_=H_group(k,:)*x_group(:,k);
            z_group=[z_group;z_];
            %err_z=[err_z;power(z_-ytest,2)];
        end
        MSEout=mse(z_group,Yzk);
        if(MSEout<0.001)
            break
        end
    end
    LMKF_label=round(z_group);
    ACC_NN_LMKF=sum(LMKF_label==Ytrain) / numel(Ytrain);
end